import request from "@/utils/request";
import axios from "axios";
//动态获取下拉编码 params为数组
const codes = {
    assetType: "/device/api/assetType/query/list",
    department: "/organization/api/organization/query/list"
};
export function fetchCodeList(query) {
    // return request({
    //     url: '/device/api/assetType/query/list',
    //     method: 'get',
    //     params: query
    // })
    const typeArray = [];
    query.map(function(e) {
        typeArray.push(
            request({
                url: codes[e],
                method: "get"
            })
        );
    });
    return axios.all(typeArray).then(
        axios.spread(function(...arg) {
            return new Promise((resolve, reject) => {
                //console.log("resp1", [...arg])
                console.log([...arg], "入参");
                const data = {};
                Array.from([...arg]).forEach((e, i) => {
                    data[query[i]] = e.data;
                });
                console.log(data, "合并的数据结果");

                resolve(data);
            });
            //console.log("resp2", resp2)
        })
    );
}

export function fetchCompanyList(query) {
    return request({
        url: "/device/api/dictionary/query/list",
        method: "get",
        params: query
    });
}

export function fetchCompany1List(query) {
    return request({
        url: "/device/api/dictionary/query/list",
        method: "get",
        params: query
    });
}
export function fetchUserList(query) {
    return request({
        url: "/user/api/user/query/list",
        method: "get",
        params: query
    });
}
export function fetchDutyList() {
    return request({
        url: "/user/api/positions/query/all/list",
        method: "get"
            // params: query
    });
}
export function updatePassword(query) {
    return request({
        url: "/user/api/user/password/update",
        method: "put",
        data: query
    });
}